package cn.educate.servlet;

import cn.educate.service.AICommandTaskManager;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/task")
public class TaskServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String taskDesc = request.getParameter("taskDesc");

        if (taskDesc == null || taskDesc.isEmpty()) {
            request.setAttribute("error", "任务描述不能为空");
            request.getRequestDispatcher("TaskManager.jsp").forward(request, response);
            return;
        }

        // 调用AICommandTaskManager的addTask方法
        AICommandTaskManager manager = AICommandTaskManager.getInstance();
        manager.addTask(taskDesc);

        // 转发回index.jsp
        response.sendRedirect("TaskManager.jsp");
    }
}
